package
{
	import flash.events.*;

	public class Controller extends EventDispatcher implements IKeyboardInputHandler
	{
		private var model:IModel;
		private var view:View;
		
		private var buttonPosition:uint=3;
		
		
		public function addView(oView:View):void
		{
			view=oView;
		}
		
		public function Controller(aModel:IModel)
		{
			this.model = aModel;
		}
		
		public function get button():uint
		{
			return buttonPosition;
		}

		
		public function keyPressHandler(event:KeyboardEvent):void
		{
			//TODO: implement function 
			//scheme A
			// [1] [2] [3] [4] [5]
			
			//scheme B
			//   [2]
			//[1][3][5]
			//   (3)		
	
//			if (event.charCode==65) view.panView(600)
//			if (event.charCode==68) view.panView(-600)
			if (event.keyCode==65) {view.lastKey="left";dispatchEvent(new Event(Event.CHANGE));}
			if (event.keyCode==68) {view.lastKey="right";dispatchEvent(new Event(Event.CHANGE));}


			if ((event.keyCode==37) && (buttonPosition>1)) buttonPosition--;
			if ((event.keyCode==39) && (buttonPosition<5)) buttonPosition++;
			
			if (buttonPosition==1) model.engineLeft();
			if (buttonPosition==5) model.engineRight();
			if ((buttonPosition==2)||(buttonPosition==4)) model.engineOutOfGear();
			if (buttonPosition==3) model.engineStoppedInGear();	
			
		}
		
	}
}